﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class Popup_Info_detail : Popup_Base
{
    public Transform m_Def;
    public Transform m_Atk;
    public Transform m_Etc;
    public Transform m_Pri;
    public Transform m_Assi;

    // 인포 패널에 보여지는 순서
    AptitudeID_New[] m_ShowOrder_Def = new AptitudeID_New[12]
    {
        AptitudeID_New.melee,
        AptitudeID_New.range,
        AptitudeID_New.magic,
        AptitudeID_New.pulse,
        AptitudeID_New.special,
        AptitudeID_New.evade,       
        AptitudeID_New.evadeMod,       
        AptitudeID_New.defDamage,       
        AptitudeID_New.defDamageMod,       
        AptitudeID_New.growHP,       
        AptitudeID_New.healRate,       
        AptitudeID_New.res,
    };

    AptitudeID_New[] m_ShowOrder_Atk = new AptitudeID_New[4]
    {
        AptitudeID_New.skillRate,
        AptitudeID_New.skillRate,       // 뭐지? --;
        AptitudeID_New.critRate,
        AptitudeID_New.critPower,          
    };

    AptitudeID_New[] m_ShowOrder_Etc = new AptitudeID_New[6]
    {
        AptitudeID_New.getFromAtk,
        AptitudeID_New.getFromHit,
        AptitudeID_New.moveSpd,
        AptitudeID_New.moveSpdMod,
        AptitudeID_New.healPower,
        AptitudeID_New.healPowerMod,       
    };

    AptitudeID_New[] m_ShowOrder_Pri = new AptitudeID_New[4]
    {
        AptitudeID_New.atkInit,
        AptitudeID_New.atkCooltime,
        AptitudeID_New.moveTime,
        AptitudeID_New.moveTimeMod,   
    };

    AptitudeID_New[] m_ShowOrder_Assi = new AptitudeID_New[2]
    {
        AptitudeID_New.attackAssist,
        AptitudeID_New.defAssist,      
    };

    public void SetPopupWithMember(MemberModel model)
    {
        DBaseCharacter_New stat = model.m_Stat.data;
        DBaseCharacter_New stat_Item = model.m_StatWithItem.data;
        UILabel label = null;
        for(int i = 0; i < m_ShowOrder_Def.Length ; i++)
        {           
            label = m_Def.Find(string.Format("text{0:00}", i + 1)).Find("value").GetComponent("UILabel") as UILabel;

            int value =  Convert.ToInt32(stat_Item[m_ShowOrder_Def[i]]) - Convert.ToInt32(stat[m_ShowOrder_Def[i]]);
            if(value > 0)            
                label.text = string.Format("{0}[55ff55]{1}[-]", stat[m_ShowOrder_Def[i]], value);            
            else            
                label.text = stat[m_ShowOrder_Def[i]].ToString();           
        }

        for (int i = 0; i < m_ShowOrder_Atk.Length; i++)
        {
            label = m_Atk.Find(string.Format("text{0:00}", i + 1)).Find("value").GetComponent("UILabel") as UILabel;

            int value = Convert.ToInt32(stat_Item[m_ShowOrder_Atk[i]]) - Convert.ToInt32(stat[m_ShowOrder_Atk[i]]);
            if (value > 0)
                label.text = string.Format("{0}[55ff55]{1}[-]", stat[m_ShowOrder_Atk[i]], value);
            else
                label.text = stat[m_ShowOrder_Atk[i]].ToString();
        }

        for (int i = 0; i < m_ShowOrder_Etc.Length; i++)
        {
            label = m_Etc.Find(string.Format("text{0:00}", i + 1)).Find("value").GetComponent("UILabel") as UILabel;

            int value = Convert.ToInt32(stat_Item[m_ShowOrder_Etc[i]]) - Convert.ToInt32(stat[m_ShowOrder_Etc[i]]);
            if (value > 0)
                label.text = string.Format("{0}[55ff55]{1}[-]", stat[m_ShowOrder_Etc[i]], value);
            else
                label.text = stat[m_ShowOrder_Etc[i]].ToString();
        }

        for (int i = 0; i < m_ShowOrder_Pri.Length; i++)
        {
            label = m_Pri.Find(string.Format("text{0:00}", i + 1)).Find("value").GetComponent("UILabel") as UILabel;

            int value = Convert.ToInt32(stat_Item[m_ShowOrder_Pri[i]]) - Convert.ToInt32(stat[m_ShowOrder_Pri[i]]);
            if (value > 0)
                label.text = string.Format("{0}[55ff55]{1}[-]", stat[m_ShowOrder_Pri[i]], value);
            else
                label.text = stat[m_ShowOrder_Pri[i]].ToString();
        }

        for (int i = 0; i < m_ShowOrder_Assi.Length; i++)
        {
            label = m_Assi.Find(string.Format("text{0:00}", i + 1)).Find("value").GetComponent("UILabel") as UILabel;

            int value = Convert.ToInt32(stat_Item[m_ShowOrder_Assi[i]]) - Convert.ToInt32(stat[m_ShowOrder_Assi[i]]);
            if (value > 0)
                label.text = string.Format("{0}[55ff55]{1}[-]", stat[m_ShowOrder_Assi[i]], value);
            else
                label.text = stat[m_ShowOrder_Assi[i]].ToString();
        }
    }

    public override void ButtonTouch(Collider collider)  // 버튼 터치 (터치 시작 끝 같은 오브젝트일때 터치 끝 시점에 호출)
    {
        Debug.Log(collider.gameObject.name);
        switch (collider.gameObject.name)
        {
            case "Button_close":
                BackButton();
                break;
        }
    }

    public override void BackButton()
    {
        ClosePopup();
    }	

	public void ClosePopup()
	{
		PopupManager.PopPopup();
	}
}